package com.beizhen.demo.controller;

import com.beizhen.demo.service.StuJournalismService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
*  学校研学总结前端控制器
*/
@RestController
    public class StuJournalismController {
    @Autowired
    private StuJournalismService stuJournalismService;

    /*public String getXML(){
        // 生成文章html 并上传url
        FileItemFactory factory = new DiskFileItemFactory(16, null);
        String textFieldName = sno + ".html";
        FileItem item = factory.createItem(textFieldName, "text/html", true, textFieldName);
        OutputStream os = item.getOutputStream();
        os.write(newHtmlText.getBytes());
        os.close();
        MultipartFile htmlFile = new CommonsMultipartFile(item);
        // 上传oss
        // 上传文章 返回文章路径（这里采用OSS上传）
        conthttp = OSSUtil.uploadFile2OSS(htmlFile, "WZ", BaseConstants.ossmap.get("WZ")).getString("path");
        return null;
    }*/

    public String ShowXML(String url){
//根据URL解析HTML页面
        StringBuilder pageHTML = new StringBuilder();
        try {
            URL urls = new URL(url);
            HttpURLConnection connection = (HttpURLConnection) urls.openConnection();
            connection.setRequestProperty("User-Agent", "MSIE&nbsp;7.0");
            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
            String line = null;
            while ((line = br.readLine()) != null) {
                pageHTML.append(line);
                pageHTML.append("\r\n");
            }
            connection.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageHTML.toString();
    }

    //进入研学总结页面
    @RequestMapping("/ConclusionXML")
    public String ConclusionXML(){
        return "base_skip";
    }
}
